package comp353Games;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.JPanel;

/**
 * ToadsAndFrogsDisplay.java offers the visual presentation of the game of Toads
 * And Frogs. It informs the user of the current layout of the game.
 *
 * @author Andre Harvey, Deanna Finke, Tyler Radley
 * @version 3/25/12
 */
public class ToadsAndFrogsDisplay extends JPanel {

    //instance variables
    /**
     * The Toads and Frogs game this will display.
     */
    ToadsAndFrogs game;
    /**
     * Number indicating a left move
     */ 
    public static final int LEFT = -1;
    /**
     * Number indicating a left move
     */ 
    public static final int RIGHT = 1;

    /**
     * Class constructor.
     *
     * @param game The ToadsAndFrogs instance this will display.
     */
    public ToadsAndFrogsDisplay(GameModel game) {
        super(new BorderLayout());
        this.game = (ToadsAndFrogs) game;
        this.setOpaque(true);
    }

    @Override
    protected void paintComponent(Graphics graphics) {
        graphics.setColor(Color.BLACK);
        int numberOfBoxes = this.game.boxesClone().length;
        for (int i = 0; i < numberOfBoxes; i++) {
            graphics.drawRect(10 + (30 * i), 10, 30, 30);
            if (this.game.boxesClone()[i] == LEFT) {
                graphics.drawString("F", 20 + (30 * i), 30);
            } else if (this.game.boxesClone()[i] == RIGHT) {
                graphics.drawString("T", 20 + (30 * i), 30);
            }
        }
    }

    @Override
    public Dimension getPreferredSize() {
        int width = 610;
        int height = 512;
        return new Dimension(width, height);
    }

    /**
     * A dimension object of the size needed to display the status messages in
     * the display
     *
     * @return The dimension object of the size needed to display the status
     * messages in the display
     */
    public Dimension getStatusBarPreferredSize() {
        int width = 40 + 140 * this.game.boxesClone().length;
        int height = 50;
        return new Dimension(width, height);
    }
}
